
package com.yulebaby.callsenter.adapter;

import android.text.TextUtils;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yulebaby.callsenter.R;
import com.yulebaby.callsenter.bean.CustomerBean;
import com.yulebaby.callsenter.bean.multiplebean.MultipleCustomerBean;
import com.yulebaby.callsenter.global.App;
import com.yulebaby.callsenter.global.Constant;
import com.yulebaby.callsenter.utils.DateUtil;
import com.yulebaby.callsenter.utils.ImageLoader;

import java.util.List;


/**
 * Author: Zhangbo
 * Time: 2016/11/13
 * <p>
 * 通话记录的适配器
 */

public class MultipleReturnVistitAdapter extends BaseMultiItemQuickAdapter<MultipleCustomerBean, BaseViewHolder> {

    public MultipleReturnVistitAdapter(List<MultipleCustomerBean> list) {
        super(list);
        addItemType(MultipleCustomerBean.TIME, R.layout.item_recycle_time);
        addItemType(MultipleCustomerBean.CUSTOMERITEM, R.layout.item_recycle_returnvisit);
    }


    @Override
    protected void convert(BaseViewHolder baseViewHolder, MultipleCustomerBean item) {
        switch (baseViewHolder.getItemViewType()) {
            case MultipleCustomerBean.TIME:
                baseViewHolder.setText(R.id.tv_time, item.getTime());
                break;
            case MultipleCustomerBean.CUSTOMERITEM:
                CustomerBean customerBean = item.getCustomerBean();
                baseViewHolder.setText(R.id.tv_phonename, checkNull(customerBean.getCustomer_name()))
                        .setText(R.id.tv_address, checkNull(customerBean.getAddress()))
                        .setText(R.id.tv_nextvist, "下次跟踪时间： " + checkNull(DateUtil.formatDateTime(customerBean.getVisit_date())))
                        .addOnClickListener(R.id.iv_robcustomer)
                        .addOnClickListener(R.id.tv_addtrack)
                        .addOnClickListener(R.id.tv_looktrack);

                switch (customerBean.getStressIntent()) {
                    case Constant.StressIntent.STATE_NEWINROOM:
                        ImageLoader.load(App.mContext, R.drawable.state_new, baseViewHolder.getView(R.id.iv_callstate));
                        break;
                    case Constant.StressIntent.STATE_STRONG:
                        ImageLoader.load(App.mContext, R.drawable.state_strong, baseViewHolder.getView(R.id.iv_callstate));
                        break;
                    case Constant.StressIntent.STATE_MIDDLE:
                        ImageLoader.load(App.mContext, R.drawable.state_middle, baseViewHolder.getView(R.id.iv_callstate));
                        break;
                    case Constant.StressIntent.STATE_COMMONLY:
                        ImageLoader.load(App.mContext, R.drawable.state_commonly, baseViewHolder.getView(R.id.iv_callstate));
                        break;
                    case Constant.StressIntent.STATE_LOW:
                    case Constant.StressIntent.STATE_NONE:
                        ImageLoader.load(App.mContext, R.drawable.state_low, baseViewHolder.getView(R.id.iv_callstate));
                        break;
                }
        }
    }


    /**
     * 判断是否为空
     *
     * @param string
     * @return
     */
    public String checkNull(String string) {
        if (TextUtils.isEmpty(string)) {
            return "";
        }
        return string;
    }
}

